Various improvements to the existing set of preload tests * Align the test names with the rest of the tests, i.e. use '-' instead of '_'. * Add feature detection to make sure the tests consistently fail in non-supporting browsers. * Make sure that download verification is based on the URL's existence in ResourceTiming, rather on the overall number of resources downloaded, which can be misleading.
diff --git a/preload/single-download-preload.html b/preload/single-download-preload.html new file mode 100644 index 0000000..c06e3e5 --- /dev/null +++ b/preload/single-download-preload.html 
@@ -0,0 +1,61 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/preload/resources/preload_helper.js"></script> +<script> + var t = async_test('Makes sure that preloaded resources are not downloaded again when used'); +</script> +<link rel=preload href="resources/dummy.js" as=script> +<link rel=preload href="resources/dummy.css" as=style> +<link rel=preload href="resources/square.png" as=image> +<link rel=preload href="resources/square.png?background" as=image> +<link rel=preload href="/fonts/CanvasTest.ttf" as=font crossorigin> +<link rel=preload href="/media/white.mp4" as=media> +<link rel=preload href="/media/sound_5.oga" as=media> +<link rel=preload href="/media/foo.vtt" as=media> +<link rel=preload href="resources/dummy.xml?foo=bar" as=foobarxmlthing> +<link rel=preload href="resources/dummy.xml"> +<body> +<script src="resources/dummy.js?pipe=trickle(d5)"></script> +<style> + #background { + width: 200px; + height: 200px; + background-image: url(resources/square.png?background); + } + @font-face { + font-family:ahem; + src: url(/fonts/CanvasTest.ttf); + } + span { font-family: ahem, Arial; } +</style> +<link rel="stylesheet" href="resources/dummy.css"> +<script src="resources/dummy.js"></script> +<div id="background"></div> +<img src="resources/square.png"> +<video src="/media/white.mp4"> + <track kind=subtitles src="/media/foo.vtt" srclang=en> +</video> +<audio src="/media/sound_5.oga"></audio> +<script> + var xhr = new XMLHttpRequest(); + xhr.open("GET", "resources/dummy.xml"); + xhr.send(); + + window.addEventListener("load", t.step_func(function() { + verifyPreloadAndRTSupport(); + setTimeout(t.step_func(function() { + verifyNumberOfDownloads("resources/dummy.js", 1); + verifyNumberOfDownloads("resources/dummy.css", 1); + verifyNumberOfDownloads("resources/square.png", 1); + verifyNumberOfDownloads("resources/square.png?background", 1); + verifyNumberOfDownloads("/fonts/CanvasTest.ttf", 1); + verifyNumberOfDownloads("resources/dummy.xml?foobar", 0); + verifyNumberOfDownloads("/media/foo.vtt", 1); + verifyNumberOfDownloads("resources/dummy.xml", 1); + // FIXME: We should verify for video and audio as well, but they seem to (flakily?) trigger multiple partial requests. + t.done(); + }), 0); + })); +</script> +<span>PASS - this text is here just so that the browser will download the font.</span>